package com.allen.apollo.config;

import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 * @Description:默认命名空间的监听
 * @Version v1.0.0
 * @date 2022/5/22 14:08
 */
@Configuration
@EnableApolloConfig
@Slf4j
public class DefaultConfigListener {

    @ApolloConfigChangeListener
    private void defaultConfigChange(ConfigChangeEvent changeEvent) {
        changeEvent.changedKeys().forEach(key ->{
            ConfigChange change = changeEvent.getChange(key);
            log.info(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s",change.getPropertyName(), change.getOldValue(),
                change.getNewValue(),change.getChangeType()));
        });
    }
}
